<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>父子组件的访问方式</title>
		<script src="../../vue/vue.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<div id="app">
			<cpn ref='aa'></cpn>
			<button type="button" @click="clicks">按钮</button>
		</div>
		<template id='cp'>
			<div>
				<h2>我是子组件</h2>
			</div>
		</template>
		<script type="text/javascript">
		/* 
		使用$children属性和$refs默认W为空 使用最多是refs	 
		 */
			var app = new Vue({
				el:'#app',
				data:{
					
				},
				methods:{
					clicks(){
						/* console.log(this.$children);
						this.$children[0].showMessage() */
						console.log(this.$refs.aa.name);//通过refs拿到子组件的值
					}
				},
				components:{
					cpn:{
						template:'#cp',
						data(){
							return{
								name:'我是谢应鹏'
							}
						},
						methods:{
							showMessage(){
								console.log('showMessage')
							}
						}
					}
				}
			});
		</script>
	</body>
</html>
